<!-- 组件说明 -->
<template>
  <div class=''>
    <van-nav-bar :title="title"
                 left-text="返回"
                 left-arrow
                 :fixed=true
                 @click-left="handleBack" />
    <van-address-edit :area-list="areaList"
                      show-postal
                      show-delete
                      show-set-default
                      show-search-result
                      :search-result="searchResult"
                      :address-info="addressInfo"
                      @save="handleSave" />
  </div>
</template>

<script>
import areaList from '../../tools/area'
export default {
  name: 'addAddress',
  data () {
    return {
      title: '新增收货地址',
      areaList,
      addressInfo: {
        id: 1,
        name: '张三',
        tel: '13506589632',
        province: '浙江省',
        city: '金华市',
        county: '义乌市',
        areaCode: '330782',
        addressDetail: '绣湖公园',
        postalCode: '322000',
        isDefault: true,
      },
      searchResult: [],
      requestType: 'post'
    };
  },
  components: {

  },
  computed: {

  },
  created () {
    /* 获取路由判断是新增还是编辑地址 */
    console.log(this.$route.query.id);
    if (this.$route.query.id) {
      this.title = '编辑收货地址';
      this.requestType = 'put';
      /* 请求获取该条地址信息 */

    }
  },
  methods: {
    /* 返回上一页 */
    handleBack () {
      this.$router.go(-1);
    },
    /* 保存/修改地址 */
    handleSave (content) {
      /* 保存修改地址成功以后，返回上一个页面 */
      console.log(content);
      this.$router.go(-1);
    }
  },
  mounted () {

  }
}
</script>

<style lang='css' scoped>
.van-address-edit {
  margin-top: 100px;
}
</style>